package lc.q51_100;

public class Q62 {
    // dp算法
    public int uniquePaths(int m, int n) {
        int[][] dp = new int[m][n];
        // 根据对称性，这里可以考虑使用一维dp
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (i == 0 & j != 0) {
                    dp[i][j] = 1;
                } else if (j == 0) {
                    dp[i][j] = 1;
                } else {
                    dp[i][j] = dp[i][j-1] + dp[i-1][j];
                }
            }
        }
        return dp[m-1][n-1];
    }

    public static void main(String[] args) {
        final Q62 q62 = new Q62();
        System.out.println(q62.uniquePaths(7,3));
    }
}
